<template>
	<view class="container">
		<view class="left-bottom-sign"></view>
		<view class="back-btn yticon"></view>
		<view class="right-top-sign"></view>
		
		
		<view class="wrapper">
			<view class="left-top-sign">REGISTER</view>
			<view class="welcome">
				欢迎注册！
			</view>
			<view class="input-content">
				<view class="input-item">
					<text class="tit">手机号码</text>
					<input 
						type="number" 
						v-model="phone"
						placeholder="请输入手机号码"
						maxlength="11"
						
					/>
				</view>
				<view class="input-item">
					<text class="tit">昵称</text>
					<input 
						 
						v-model="name"
						placeholder="请设置昵称"
						
						
						
						
					/>
				</view>
				<view class="input-item flex-item">
					<view class="left">
						<text class="tit">请输入验证码</text>
						<input 
							
							v-model="code"
							placeholder="请输入验证码"
							
							
							
						/>
					</view>
					<view class="right" @click="getCode">
						{{btntip}}
					</view>
				</view>
				<view class="input-item">
					<text class="tit">服务人</text>
					<input 
						
						v-model="link_person"
						placeholder="请输入服务人"
						
						
						@blur="searchjiedian" 
						
						
						
					/>
				</view>
				<view class="input-item">
					<text class="tit">请设置登录密码</text>
					<input 
						
						v-model="pwd"
						placeholder="请设置登录密码"
						
						
						password 
						
						
						
					/>
				</view>
				<view class="input-item">
					<text class="tit">请设置支付密码</text>
					<input 
						 
						v-model="jy_pwd"
						placeholder="请设置支付密码"
						
						password 
						
					/>
				</view>
				
				<view v-if="canedit" class="input-item">
					<text class="tit">推荐码</text>
					{{invite_code}}
				</view>
				<view v-else class="input-item">
					<text class="tit">推荐码</text>
					<input 
						
						v-model="invite_code"
						placeholder="推荐码"
						
					/>
				</view>
			</view>
			<button class="confirm-btn" @click="register">注册</button>
			  <!-- #ifdef H5 -->
			<view class="down-wrap">
				<text style="color:#4399fc;" @click="getapp">已有账号前去下载APP</text>
			</view>
			  <!-- #endif -->
			
		</view>
		
	</view>
</template>

<script>
	
	
	export default{
		data(){
			return {
				link_person:'',
				btntip: '点击获取验证码',
				phone: '',
				pwd: '',
				timer:null,
				time:59,
				name:'',
				code:'',
				jy_pwd:'',
				invite_code:'',
				canedit:''
			}
		},
		onLoad(options){
			this.invite_code=options.invite
			this.canedit=options.invite
		},
		methods: {
			getapp(){
				window.location.href="https://download.huayuyangchu.cn"
			},
			searchjiedian(e){
				
				let that=this
				
				if(!e.detail.value){
					
					return
				}
				
				
				
				
				that.apipost('/api/auth/link_person',{
					username:e.detail.value,
					
				},true).then(res => {
					if(res.Code==10200){
						uni.showToast({
						    title: res.Message,
						    duration:4000,
							icon:'none'
						});
						
					}
					
				}).catch(err=>{
					console.log(err)
				});
			},
			register(){
				let that=this
				
				if(this.phone==''){
					uni.showToast({
					    title: '请输入手机号',
					    duration:4000,
						icon:'none'
					});
					return
				}
				if(this.code==''){
					uni.showToast({
					    title: '请输入手机验证码',
					    duration:4000,
						icon:'none'
					});
					return
				}
				if(this.name==''){
					uni.showToast({
					    title: '请输入昵称',
					    duration:4000,
						icon:'none'
					});
					return
				}
				if(this.pwd==''){
					uni.showToast({
					    title: '请设置登录密码',
					    duration:4000,
						icon:'none'
					});
					return
				}
				let reg=/^\d{6}$/
				if(!reg.test(this.jy_pwd)){
					uni.showToast({
					    title: '支付密码为六位数字',
					    duration:4000,
						icon:'none'
					});
					return
				}
				
				
				
				
				
				
				that.apipost('/api/auth/signup',{
					phone:that.phone,
					link_person:that.link_person,
					pwd:that.pwd,
					name:that.name,
					jy_pwd:that.jy_pwd,
					invite_code:that.invite_code,
					code:that.code
				},true).then(res => {
					if(res.Code==10200){
						// #ifdef H5
							window.location.href="https://download.huayuyangchu.cn"
						// #endif
			
						
						uni.showToast({
						    title: res.Message,
						    duration:4000,
							icon:'none'
						});
						
					}
					
				}).catch(err=>{
					console.log(err)
				});
				
			},
			getCode(){
				let that=this
				
				if(this.phone==''){
					uni.showToast({
					    title: '请输入手机号',
					    duration:4000,
						icon:'none'
					});
					return
				}
				if(that.time!=59){
					return
				}
				
				that.timer=setInterval(function(){
					
					if(that.time==1){
						that.btntip='点击获取验证码'
						clearInterval(that.timer)
						that.time=59
					}else{
						that.btntip=--that.time+'s后获取'
					}
					
				},1000)
				
				that.apiget('/api/auth/SendMobileMsg',{
					phone:that.phone,
					
				},true).then(res => {
					if(res.Code==10200){
						uni.showToast({
						    title: res.Message,
						    duration:4000,
							icon:'none'
						});
						
					}
					
				}).catch(err=>{
					console.log(err)
				});
			},
			loginClick(){
				
				
				let that=this
				if(this.mobile==''||this.pwd==''){
					uni.showToast({
					    title: '账号密码不能为空',
					    duration:4000,
						icon:'none'
					});
					return
				}
				
				that.apipost('/api/auth/login',{
					mobile:that.mobile,
					pwd:that.pwd
				},true).then(res => {
					if(res.Code==10200){
						uni.setStorageSync("auth_token",res.Data)
						uni.setStorageSync("mobile",that.mobile)
						uni.switchTab({
						    url: '/pages/index/index'
						});
					}
					
				}).catch(err=>{
					console.log(err)
				});
			},
			switchpage(path){
				if(path){
					uni.switchTab({
					    url: '/pages/index/index'
					});
				}else{
					uni.showToast({
					    title: '暂未开放',
					    duration:4000,
						icon:'none'
					});
				}
			},
			enterpage(path){
				
				if(path){
					
					uni.navigateTo({
					    url: path
					});
				}else{
					uni.showToast({
					    title: '暂未开放',
					    duration:4000,
						icon:'none'
					});
				}
			}
			
		},

	}
</script>

<style lang='scss'>
	.down-wrap{
		display:flex;
		justify-content: center;
		padding-top:35rpx;
	}
	.flex-item{
		display:flex;
		flex-direction:row!important;
		justify-content:space-between!important;
		align-items: center!important;
	}
	.flex-item{
		display:flex;
		align-items: center;
	}
	.container {
		box-sizing: border-box;
	   
	    position: relative;
	    width: 100vw;
	    
	   
	    background: #fff;
	}
	page{
		background: #fff;
		overflow: hidden!important;
		width:100%;
	}
	.container{
		overflow-x: hidden!important;
		padding-top: 125rpx;
		position:relative;
		width: 100%;
		
		
		background: #fff;
	}
	.wrapper{
		overflow: hidden!important;
		position:relative;
		z-index: 90;
		background: #fff;
		padding-bottom: 40rpx;
	}
	.back-btn{
		position:absolute;
		left: 40rpx;
		z-index: 9999;
		padding-top: var(--status-bar-height);
		top: 40rpx;
		font-size: 40rpx;
		color: $font-color-dark;
	}
	.left-top-sign{
		font-size: 120rpx;
		color: $page-color-base;
		position:relative;
		left: -16rpx;
	}
	.right-top-sign{
		position:absolute;
		top: 80rpx;
		right: -30rpx;
		z-index: 95;
		&:before, &:after{
			display:block;
			content:"";
			width: 400rpx;
			height: 80rpx;
			background: #b4f3e2;
		}
		&:before{
			transform: rotate(50deg);
			border-radius: 0 50px 0 0;
		}
		&:after{
			position: absolute;
			right: -198rpx;
			top: 0;
			transform: rotate(-50deg);
			border-radius: 50px 0 0 0;
			/* background: pink; */
		}
	}
	.left-bottom-sign{
		position:absolute;
		left: -270rpx;
		bottom: -320rpx;
		border: 100rpx solid #d0d1fd;
		border-radius: 50%;
		padding: 180rpx;
	}
	.welcome{
		position:relative;
		left: 50rpx;
		top: -90rpx;
		font-size: 46rpx;
		color: #555;
		text-shadow: 1px 0px 1px rgba(0,0,0,.3);
	}
	.input-content{
		box-sizing: border-box;
		width:100%;
		overflow: hidden;
		padding: 0 60rpx;
	}
	.input-item{
		display:flex;
		flex-direction: column;
		align-items:flex-start;
		justify-content: center;
		padding: 0 30rpx;
		background:$page-color-light;
		height: 120rpx;
		border-radius: 4px;
		margin-bottom: 50rpx;
		&:last-child{
			margin-bottom: 0;
		}
		.tit{
			height: 50rpx;
			line-height: 56rpx;
			font-size: $font-sm+2rpx;
			color: $font-color-base;
		}
		input{
			height: 60rpx;
			font-size: $font-base + 2rpx;
			color: $font-color-dark;
			width: 100%;
		}	
	}

	.confirm-btn{
		width: 630rpx;
		height: 76rpx;
		line-height: 76rpx;
		border-radius: 50px;
		margin-top: 70rpx;
		background: $uni-color-primary;
		color: #fff;
		font-size: $font-lg;
		&:after{
			border-radius: 100px;
		}
	}
	.forget-section{
		font-size: $font-sm+2rpx;
		color: $font-color-spec;
		text-align: center;
		margin-top: 40rpx;
	}
	.register-section{
		position:absolute;
		left: 0;
		bottom: 50rpx;
		width: 100%;
		font-size: $font-sm+2rpx;
		color: $font-color-base;
		text-align: center;
		text{
			color: $font-color-spec;
			margin-left: 10rpx;
		}
	}
</style>
